<%@ page import="zhangcy.day0109.carlottery.dao.UserDao" %>
<%@ page import="zhangcy.day0109.carlottery.dao.impl.UserDaoImpl" %>
<%@ page import="zhangcy.day0109.carlottery.po.User" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="zhangcy.day0109.carlottery.service.UserMgr" %><%--
  Created by IntelliJ IDEA.
  User: 小香菜
  Date: 2023/1/9
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>保存用户信息</title>
  <%
    /* 解决request请求参数中出现的中文乱码 */
//      request.setCharacterEncoding("UTF-8");
    /* 获取addUser.jsp页面中，用户名和手机号 */
      String userName = request.getParameter("userName");
      String phone = request.getParameter("phone");

//      多态体现，创建userDao数据访问层
      UserDao userDao = new UserDaoImpl();
//      创建User对象，用来创建添加用户信息
      User user = new User();
      user.setUserName(userName);
      user.setPhone(phone);
//      中签编码 调用随机生成的方法
      String markNo = UserMgr.getNumSmallCharRandom(10);
      user.setMarkNo(markNo);
      SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
//      当前系统时间
      user.setOpenDate(sf.format(new Date()));
      int addRes = userDao.insertUser(user);
      if (addRes > 0) {
//        跳转到index.jsp页面
//        转发 和 重定向
        request.getRequestDispatcher("index.jsp").forward(request, response);
      }else {
        out.println("添加失败");
      }
  %>
</head>
<body>

</body>
</html>
